package com.xl.frontendproject;

import java.io.*;

import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
    // 存储要显示的消息
    private String message;
    public void init() {
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");

        // 获取用于向客户端输出的PrintWriter对象
        PrintWriter out = response.getWriter();
        // 输出HTML的开始标签
        out.println("<html><body>");
        // 输出包含消息的标题
        out.println("<h1>" + message + "</h1>");
        // 输出HTML的结束标签
        out.println("</body></html>");
    }

    /**
     * 销毁Servlet时调用的方法，这里为空实现
     */
    public void destroy() {
    }
}